package com.elder.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.elder.business.domain.EgressRegisterRecordsVO;
import com.elder.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.elder.common.annotation.Log;
import com.elder.common.core.controller.BaseController;
import com.elder.common.core.domain.AjaxResult;
import com.elder.common.enums.BusinessType;
import com.elder.business.domain.EgressRegisterRecords;
import com.elder.business.service.IEgressRegisterRecordsService;
import com.elder.common.utils.poi.ExcelUtil;
import com.elder.common.core.page.TableDataInfo;

/**
 * 外出申请记录Controller
 * 
 * @author zyk
 * @date 2023-11-26
 */
@RestController
@RequestMapping("/business/egressRecords")
public class EgressRegisterRecordsController extends BaseController
{
    @Autowired
    private IEgressRegisterRecordsService egressRegisterRecordsService;

    /**
     * 查询外出申请记录列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(String elderName,String startTime,String endTime,String applyStatus,Integer pageNum,Integer pageSize) {
        return egressRegisterRecordsService.getEgressRegisterRecords(elderName,startTime,endTime,applyStatus,pageNum,pageSize);
    }

    /**
     * 导出外出申请记录列表
     */
//    @PreAuthorize("@ss.hasPermi('business:egressRecords:export')")
//    @Log(title = "外出申请记录", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, EgressRegisterRecords egressRegisterRecords)
//    {
//        List<EgressRegisterRecords> list = egressRegisterRecordsService.selectEgressRegisterRecordsList(egressRegisterRecords);
//        ExcelUtil<EgressRegisterRecords> util = new ExcelUtil<EgressRegisterRecords>(EgressRegisterRecords.class);
//        util.exportExcel(response, list, "外出申请记录数据");
//    }

    /**
     * 获取外出申请记录详细信息
     */
    @Anonymous
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(egressRegisterRecordsService.selectEgressRegisterRecordsById(id));
    }

    /**
     * 新增外出申请记录
     */
    @Anonymous
    @Log(title = "外出申请记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EgressRegisterRecordsVO egressRegisterRecords)
    {
        return toAjax(egressRegisterRecordsService.insertEgressRegisterRecords(egressRegisterRecords));
    }

    /**
     * 修改外出申请记录
     */
    @Anonymous
    @Log(title = "外出申请记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EgressRegisterRecordsVO egressRegisterRecords)
    {
        return toAjax(egressRegisterRecordsService.updateEgressRegisterRecords(egressRegisterRecords));
    }

    /**
     * 删除外出申请记录
     */
    @Anonymous
    @Log(title = "外出申请记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(egressRegisterRecordsService.deleteEgressRegisterRecordsByIds(ids));
    }

    @Anonymous
    @RequestMapping("/approve")
    public AjaxResult approveEgressApply(Long elderId ,String notes,String applyStatus){
        return egressRegisterRecordsService.updateEgressRegisterApprove(elderId,applyStatus,notes);
    }
}
